package com.bishe.bishe.Service.ServiceImpl;

import com.bishe.bishe.Service.CommentService;
import com.bishe.bishe.dao.mapper.CommentMapper;
import com.bishe.bishe.pojo.Comments;
import com.bishe.bishe.pojo.Species;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CommentServiceImpl implements CommentService
{

    @Autowired
    private CommentMapper commentMapper;
    @Override
    public PageInfo<Comments> findall(int page, int size) {
        PageHelper.startPage(page, size);
        List<Comments> list=commentMapper.findall();
        PageInfo<Comments> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int add(Comments comments) {
       return commentMapper.insert(comments);
    }

    @Override
    public int update(Integer commentId) {
        return commentMapper.update(commentId);
    }

    @Override
    public List<Comments> findById(Integer commentId) {
        return commentMapper.findById(commentId);
    }

    @Override
    public PageInfo <Comments> findPage(Map<String, Object> searchMap, int page, int size) {
        PageHelper.startPage(page,size);
        if (searchMap!=null){
            if (searchMap.get("name")!=null&&!"".equals(searchMap.get("name"))){
                return  new PageInfo<>(commentMapper.findByOrderId((Integer) searchMap.get("name")));
            }else {
                return null;
            }
        }else {
            return null;
        }
    }

    @Override
    public List <Comments> findnumber() {
        return commentMapper.findnumber();
    }

    @Override
    public List <Comments> findByOrderId(Integer orderId) {
        return commentMapper.findByOrderId(orderId);
    }


}
